package com.example.iqiyitest.adapter;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.example.iqiyitest.R;
import com.example.iqiyitest.activity.DetailForMovieActivity;
import com.example.iqiyitest.info.MovieDetailInfo;
import com.example.iqiyitest.utils.ImageLoader;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;



public class MovieListAdapter extends BaseAdapter {
	private ArrayList<MovieDetailInfo> list;
	private Context context;
	private int itemResource;
	private ImageLoader mImageLoader;
	private int lastFocus = 0;
	View rootView;
	ImageView iconImage;
	TextView appName;
	public MovieListAdapter(Context context, int itemResource, ArrayList<MovieDetailInfo> list) {
		this.context = context;
		this.itemResource = itemResource;
		this.list = list;
		mImageLoader = ImageLoader.getInstance();// zhangzhl--后进先出法 ，优先加载 最后一个
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list==null?0:list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(context).inflate(itemResource, null);
		iconImage = (ImageView) view.findViewById(R.id.image_view);
		appName = (TextView) view.findViewById(R.id.name_text);
		mImageLoader.loadImage(
				list.get(position).getPosterLocalImg()
						, iconImage, true);
		Log.e("放图片放图片"+position+"======================================", "======================================");
		view.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Log.e("iqiyi", "点击");
				// TODO Auto-generated method stub
				Intent intent=new Intent(context,DetailForMovieActivity.class);
				 Bundle bundle = new Bundle();
				  bundle.putSerializable("data",list.get(position));
				  intent.putExtras(bundle);
				  context.startActivity(intent);
			}
		});
		return view;
	}
}
